﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Configuration;
using System.Collections.Specialized;
using System.Web;

namespace DIS.Portal.Biz
{
    public class SupportBiz
    {
        public static string GetCertificate()
        {
            try
            {
                string costRankStr = WebConfigurationManager.AppSettings["Cert"];
                return costRankStr;
            }
            catch (Exception)
            {

                return "";
            }

        }

        public static bool WriteCertificate(string certificate)
        {

            Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings");
            if (appSetting.Settings["Cert"] == null)//如果不存在此节点,则添加
            {
                appSetting.Settings.Add("Cert", certificate);
            }
            else//如果存在此节点,则修改
            {
                appSetting.Settings["Cert"].Value = certificate;
            }
            config.Save();
            return true;
        }

        public static decimal GetAllowanceMoney()
        {
            try
            {
                decimal allowanceMoney = decimal.Parse(WebConfigurationManager.AppSettings["AllowanceMoney"]);
                return allowanceMoney;
            }
            catch (Exception)
            {

                return 0;
            }
        }

        public static bool WriteAllowanceMoney(string allowanceMoney)
        {

            Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
            AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings");
            if (appSetting.Settings["AllowanceMoney"] == null)//如果不存在此节点,则添加
            {
                appSetting.Settings.Add("AllowanceMoney", allowanceMoney);
            }
            else//如果存在此节点,则修改
            {
                appSetting.Settings["AllowanceMoney"].Value = allowanceMoney;
            }
            config.Save();
            return true;
        }
    }
}
